package homework;

import org.junit.Test;

import java.util.Arrays;
import java.util.Random;
public class   Selectsortext {
    @Test
    public void testSelectSort02() {
        int[] arr = randomArray(20, 100);
        System.out.println("排序前:" + Arrays.toString(arr));
        Arrays.sort(arr);
        System.out.println("排序后:" + Arrays.toString(arr));
    }


    public void insertSort(int[] arr) {
        for (int i = 1; i < arr.length; i++) {
            int temp=arr[i];
            int j=i-1;
            for(;j>=0;j--){
                if(temp<arr[j]){
                    arr[j+1]=arr[j];
                }else {
                    break;
                }
            }
            arr[j+1]=temp;
        }
    }



    public int[] randomArray(int length, int bound) {
        int[] result = new int[length];
        boolean[] flag = new boolean[bound + 1];
        Random r = new Random();
        for (int i = 0; i < length; i++) {
            int temp = r.nextInt(bound) + 1;
            if (flag[temp]) {
                i--;
                System.out.println("重复出现");
            } else {
                result[i] = temp;
                flag[temp] = true;
            }
        }return result;
    }
   @Test
    public void arraycopytest(){
        int[] src={28,29,31};
        int[] target=new int[5];
        System.arraycopy(src,0,target,0,3);
       System.out.println(Arrays.toString(target));
   }
}